package org.jeecg.common.modules.settlement.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.jeecg.common.modules.doctor.entity.Doctor;
import org.jeecg.common.modules.order.entity.OrderInfo;
import org.jeecg.common.modules.settlement.entity.Settlement;
import org.jeecg.common.modules.settlement.mapper.SettlementMapper;
import org.jeecg.common.modules.settlement.service.ISettlementService;
import org.jeecg.common.modules.settlement.vo.SettlementReqVo;
import org.jeecg.common.util.enums.SettlementStatusEnum;
import org.jeecg.common.util.enums.SettlementTypeEnum;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @Description: settlement
 * @Author: jeecg-boot
 * @Date:   2020-09-03
 * @Version: V1.0
 */
@Service
public class SettlementServiceImpl extends ServiceImpl<SettlementMapper, Settlement> implements ISettlementService {
    @Resource
    private SettlementMapper settlementMapper;

    @Override
    public Settlement initSettlement(OrderInfo orderInfo) {
        Settlement settlement = new Settlement();
        settlement.setAmount(orderInfo.getAmount());
        settlement.setRelationId(orderInfo.getId());
        settlement.setType(SettlementTypeEnum.DOCTOR_SERVICE.getCode());
        settlement.setStatus(SettlementStatusEnum.WAIT.getCode());
        settlement.setCreateBy("confirmJob");
        settlement.setCreateTime(new Date());
        save(settlement);
        return settlement;
    }

    @Override
    public Settlement getSettlementInfo(String orderId){
        LambdaQueryWrapper<Settlement> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(Settlement::getRelationId,orderId);
        return getOne(queryWrapper);
    }

    @Override
    public List<SettlementReqVo> selectSettlementInfo(String orderId, String userName, String doctorName, Integer dataStart, Integer pageSize){
        return settlementMapper.selectSettlementInfo(orderId,userName,doctorName,dataStart,pageSize);
    }

    @Override
    public int getSettlementCount(String orderId, String userName, String doctorName){
        return settlementMapper.getSettlementCount(orderId,userName,doctorName);
    }
}
